package org.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import org.dk.constant.DataResultConstant;
import org.dk.domain.DataResult;
import org.dk.em.DataResultEnum;
import org.dk.pageInfo.PageInfo2;
import org.dk.pojo.TbBrand;
import org.dk.service.BrandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("brandController")
public class BrandController {

    @Reference
    private BrandService brandService;

    @RequestMapping("brandToShow")
    public String BrandToShow(){
        return "admin/brand";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public DataResult selectAll(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                      @RequestParam(required = false, defaultValue = "5") Integer pageSize){
        PageInfo2<TbBrand> selevt = brandService.selectBrand(pageNum, pageSize);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(selevt);
    }

    @RequestMapping("insert")
    @ResponseBody
    public DataResult insert(TbBrand tbBrand){
        Boolean b = brandService.insertinto(tbBrand);
        return new DataResult(100,"增加成功");
    }

    @RequestMapping("delete")
    @ResponseBody
    public DataResult delete(Long id){
        Boolean b =  brandService.deleteByid(id);
        return new DataResult(DataResultConstant.SUCCESS_CODE,DataResultConstant.SUCCESS_MESSAGE);
    }

    @RequestMapping("updata")
     @ResponseBody
     public DataResult updata(Long id){
         TbBrand updata = brandService.updata(id);
         return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(updata);
     }

    @RequestMapping("updatas")
       @ResponseBody
    public DataResult updatas(TbBrand tbBrand){
        Boolean b = brandService.updatas(tbBrand);
        return new DataResult(100,"修改成功");
    }
}
